<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <script src="/static/vue/vue.js"></script>
    <script src="/static/axios/axios.js"></script>
    <%--    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>--%>
    <script src="https://unpkg.com/axios@0.21.1/dist/axios.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>图书商城-查看商品详情</title>
</head>
<style>
    #bd {
        position: relative;
        overflow: hidden;
    }

    #bd {
        width: auto !important;
    }

    #detail {
        z-index: 99999999;
        position: relative;
        margin: 10px auto 0;
        width: 1140px;
        color: #3C3C3C;
    }

    #detail .tb-detail-bd {
        _position: relative;
        margin-bottom: 20px;
        border: 1px solid #E8E8E8;
    }

    #detail .tb-summary {
        float: left;
        width: 100%;
    }

    #detail .tb-summary .tb-item-info {
        margin-right: 198px;
        border-right: 1px solid #E8E8E8;
    }

    #detail .tb-summary .tb-item-info .tb-item-info-l {
        float: left;
        padding: 20px 0 20px 20px;
        width: 400px;
        position: relative;
    }

    .tb-gallery {
        margin-bottom: 18px;
        width: 400px;
        overflow: hidden;
        *zoom: 1;
    }

    .tb-gallery .tb-main-pic {
        width: 400px;
        height: 400px;
        overflow: hidden;
    }

    #detail .tb-summary .tb-item-info .tb-item-info-r {
        float: left;
        padding: 0 20px 20px 0;
        width: 498px;
    }

    #detail .tb-summary .tb-item-info .tb-item-info-r .tb-property {
        z-index: 1;
        position: relative;
    }

    #detail .tb-summary .tb-item-info .tb-item-info-r .tb-property .tb-wrap {
        padding-left: 18px;
    }

    #detail .tb-property-x .tb-title {
        padding: 20px 0 10px !important;
    }

    #detail .tb-title .tb-main-title {
        min-height: 21px;
        _height: 21px;
        font-size: 16px;
        font-weight: 700;
        line-height: 21px;
        color: #3C3C3C;
    }

    #detail .tb-title .tb-subtitle {
        margin-top: 5px;
        padding-bottom: 15px;
        color: #6C6C6C;
        border-bottom: 1px dotted #D9D9D9;
    }

    #detail .tb-editor-menu {
        float: left;
        z-index: 9999;
        position: absolute;
        top: -11px;
        right: 0;
        line-height: 21px;
        background: #FFF;
    }

    .tb-banner {
        position: relative;
    }

    #detail .tb-property-x .tb-meta {
        padding: 10px;
        background-color: #FFF2E8;
    }

    #detail .tb-property-x .tb-meta li {
        margin-bottom: 0;
    }

    .tb-meta .tb-property-type {
        display: inline;
        float: left;
        width: 60px;
        color: #6c6c6c;
    }

    .tb-meta .tb-property-cont {
        overflow: hidden;
        *zoom: 1;
    }


    #bd .tb-rmb, #bd .del .tb-rmb {
        font-family: arial;
        font-weight: 400;
        margin-right: 4px;
    }

    #bd .tb-rmb-num {
        font-family: verdana, arial;
    }

    #detail .tb-property-x .tb-counter {
        position: absolute;
        top: 6px;
        right: 10px;
    }

    #detail .tb-counter .tb-property-type {
        display: none;
    }

    #bd .tb-meta li {
        margin-bottom: 2px;
        line-height: 24px;
    }

    #detail .tb-property-x .tb-counter .tb-rate-counter {
        padding-right: 9px;
    }

    #detail .tb-property-x .tb-key {
        padding-left: 18px;
        padding-bottom: 5px;
        margin-bottom: 20px;
    }

    #detail .tb-key {
        z-index: 6;
        position: relative;
        margin: -9px 0 29px -9px;
        padding: 9px 0 0 9px;
        border: 1px solid #FFF;
    }

    #detail .tb-key .tb-skin {
        position: relative;
    }

    div {
        display: block;
    }

    #detail .tb-key dl {
        margin-bottom: 10px;
    }

    #bd .tb-clearfix, #bd .tb-key dl, #bd .tb-other, #bd .combo ul, #bd .scrolling-promo-content, .tb-popup-share .tb-tab-hd {
        *zoom: 1;
    }

    #bd .tb-amount {
        line-height: 28px;
    }

    #detail .tb-key dl dt {
        float: left;
        margin-right: 5px;
        width: 55px;
        color: #6C6C6C;
    }

    blockquote, body, button, dd, dl, dt, fieldset, form, h1, h2, h3, h4, h5, h6, hr, input, legend, li, ol, p, pre, td, textarea, th, ul {
        margin: 0;
        padding: 0;
    }

    #bd .tb-stock .tb-disable-increase, #bd .tb-stock .tb-disable-increase:hover, #bd .tb-stock .tb-disable-reduce, #bd .tb-stock .tb-disable-reduce:hover {
        color: #ccc;
        cursor: not-allowed;
        background-color: #ededed;
    }

    #detail .tb-key .tb-stock .tb-stock-num, #detail .tb-key .tb-stock input {
        float: left;
        margin: 0;
        padding: 0;
        width: 48px;
        height: 26px;
        font-size: 16px;
        line-height: 26px;
        text-align: center;
        color: #666;
        border: 1px solid #CCC;
        outline: 0;
        background: #FFF;
        ime-mode: disabled;
    }

    #bd .tb-stock .tb-increase {
        border-left: 0 !important;
        margin-right: 8px;
    }

    dt {
        display: block;
    }

    #detail .tb-key .tb-stock {
        position: relative;
        float: left;
    }
</style>
<body>
<div id="app">
    <el-menu class="el-menu-demo" mode="horizontal">
        <el-menu-item index="1"><a href="/">首页</a></el-menu-item>
        <el-menu-item index="2"><a href="/goShoppingCart">购物车</a></el-menu-item>
        <el-menu-item index="3"><a href="/goUser">${user.userName} 个人中心 </a></el-menu-item>
        <c:if test="${user.id!=null}">
            <el-menu-item index="3"><a href="/logout">注销 ${user.userName}</a></el-menu-item>
        </c:if>
    </el-menu>

    <div id="bd">
        <div id="detail">
            <div class="tb-detail-bd tb-clear">
                <div class="tb-summary tb-clear">
                    <div class="tb-item-info tb-clear">
                        <div class="tb-item-info-l">
                            <div class="tb-gallery">
                                <div class="tb-booth tb-pic tb-main-pic">
                                    <img :src="goods.goodsImage" alt="">
                                </div>
                            </div>
                        </div>
                        <div class="tb-item-info-r">
                            <div class="tb-property tb-property-x">
                                <div class="tb-wrap tb-wrap-newshop">
                                    <div class="tb-title">
                                        <h3 class="tb-main-title">
                                            标题： {{goods.goodsName}}
                                        </h3>
                                        <p class="tb-subtitle"></p>
                                        <div class="tb-editor-menu"></div>
                                    </div>
                                    <div class="tb-banner"></div>
                                    <ul class="tb-meta">
                                        <li class="tb-detail-price tb-clear J_PriceItem">
                                            <span class="tb-property-type">价格</span>
                                            <div class="tb-property-cont">
                                                <strong style="font-size: 24px; color: rgb(255, 68, 0); font-weight: 700; text-decoration: none;">
                                                    <em class="tb-rmb">￥</em>
                                                    <em class="tb-rmb-num">{{goods.goodsPrice}}</em>
                                                </strong>
                                            </div>
                                        </li>
                                        <li class="tb-counter">
                                            <span>销量</span>
                                            <div>
                                                <h3> {{goods.goodsSaleCount}} 件</h3>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <div style="margin: 20px;padding: 40px">
                                <span>
                                    购买数量
                                </span>
                                <input type="text" v-model="buyCount">
                                <span>库存</span>
                                {{goods.goodsStock}}
                            </div>
                            <br>
                            <div style="margin: 30px;padding: 40px">
                                <el-button @click="buy" type="success">购买</el-button>

                                <el-button @click="addToCart" type="primary">加入购物车</el-button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            message: "33",
            name: "like",
            goods: "",
            buyCount: 1,
        },
        created() {
            this.view()
        },
        methods: {
            buy() {
                const h = this.$createElement;
                axios.request({
                    url: "/goods/buy/" + this.goods.id + "/" + this.buyCount,
                    method: "get",
                }).then(res => {
                    if (res.data.code == 101) {
                        window.location.href = "/goLogin"
                        // 未登录
                        this.message = res.data.message;
                        this.$notify({
                            title: '提示',
                            message: h('i', { style: 'color: teal'}, this.message)
                        });
                    } else if (res.data.code == 202) {
                        // 库存不足
                        this.message = res.data.message;
                        this.$notify({
                            title: '提示',
                            message: h('i', { style: 'color: teal'}, this.message)
                        });
                    } else {
                        // 购买成功，跳转购买成功页面
                        window.location.href = "/goSuccess"
                    }
                });
            },
            addToCart() {
                axios.request({
                    url: "/goods/addToCart/" + this.goods.id + "/" + this.buyCount,
                    method: "get",
                }).then(res => {
                    if (res.data.code == 101) {
                        window.location.href = "/goLogin"
                    } else if (res.data.code == 202) {
                        // 库存不足
                    } else {
                        const h = this.$createElement;
                        // 添加成功，跳转到首页
                        this.message = res.data.message;
                        this.$notify({
                            title: '提示',
                            message: h('i', { style: 'color: teal'}, this.message)
                        });
                        // 跳转到购物车页面
                        window.location.href = "/goShoppingCart"
                    }
                });
            },
            view() {
                axios.request({
                    url: "/goods/view/" +${id},
                    method: "get",
                }).then(res => {
                    this.goods = res.data.data
                });
            },
        }
    })
</script>
</body>
</html>